package test0ne.多线程;

import java.sql.Time;

public class ThreadState {

    public static void main(String[] args) {
        new Thread(new TimeWaiting(), "TimeWaiting Thread").start();
        new Thread(new Waiting(), "Waiting Thread").start();

        //使用两个Blocked线程，一个获取锁成功，一个获取索失败
        new Thread(new Blocked(), "Blocked Thread——1").start();
        new Thread(new Blocked(), "Blocked Thread——2").start();
    }

    //不断进行睡眠
    static class TimeWaiting implements Runnable{
        @Override
        public void run() {
            while (true) {
                SleepUtils.second(100);
            }
        }
    }

    //该线程在Waiting.class等待
    static class Waiting implements Runnable{
        @Override
        public void run() {
            while (true) {
                synchronized (Waiting.class) {
                    try {
                        Waiting.class.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    //该线程在Blocked.class实例上加锁后，不会释放锁
    static class Blocked implements Runnable{
        @Override
        public void run() {
            synchronized (Blocked.class) {
                while (true) {
                    SleepUtils.second(100);
                }
            }
        }
    }


}
